<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="<%=request.getContextPath()%>/static/sys/user-manager/css/userList.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<center><h2>新增角色</h2></center>
		<hr>
		<form action="<%=request.getContextPath() %>/role/RoleServlet?command=add" method="post" onsubmit="return validate();">
    	   角色名称:<input type="text" name="name" value="" id="name" onblur="upperCase(this)"/>
          <font color="#CCCC66"><span id="nameInfo"></span></font>
          <br><br>		
       	   备　　注:<input type="text" name="memo" value="" id="name"/>
          <span id="nameInfo"></span><br><br>
        <input type="submit" value="新增" onclick="return confirm('是否新增？');">
     </form>
<script type="text/javascript">
	//用户名唯一验证
	    function upperCase(name)
      {
        	
       	var xmlhttp;
        var roleName = document.getElementById("name").value;
        
       	if (window.XMLHttpRequest)
       	  {// code for IE7+, Firefox, Chrome, Opera, Safari
       	  xmlhttp=new XMLHttpRequest();
       	  }
      	else
       	  {// code for IE6, IE5
       	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       	  }
       	xmlhttp.onreadystatechange=function()
       	  {
       	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
       	    {
       		var print = xmlhttp.responseText
       	    document.getElementById("nameInfo").innerHTML=print;
       	    }
       	  }
       	  
       	xmlhttp.open("post","<%=request.getContextPath()%>/role/RoleServlet?command=onlyRoleName&name="+roleName,true);
       	xmlhttp.send();
     } 
	    function validate() {
	    	var flag = true;
	    	var name = document.getElementById('name').value;
	    	if (name == '') {
	    		document.getElementById('nameInfo').innerHTML = '角色名不能为空！';
	    		flag = false;
	    	} else {
	    		document.getElementById('nameInfo').innerHTML = '';
	    	}
	    	return flag;
	    }
</script>
</body>
</html>